#include "ChatDialog/chatuserwid.h"
#include "ChatDialog/ui_chatuserwid.h"

#include <QPixmap>
#include <QDebug>

ChatUserWid::ChatUserWid(QWidget *parent)
    : ListItemBase(parent)
    , ui(new Ui::ChatUserWid)
{
    ui->setupUi(this);
    SetItemType(ListItemType::CHAT_USER_ITEM); //
}

ChatUserWid::~ChatUserWid(){
    delete ui;
}

// 设置一条聊天消息的内容
void ChatUserWid::SetInfo(QString name, QString head, QString msg){
    _name = name;
    _head = head;
    _msg = msg;
    // 加载图片
    QPixmap pixmap(_head);

    // 设置图片自动缩放
    ui->icon_lb->setPixmap(pixmap.scaled(ui->icon_lb->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
    ui->icon_lb->setScaledContents(true);

    ui->user_name_lb->setText(name);
    ui->user_chat_lb->setText(msg);
}
